import { Injectable } from '@nestjs/common';
import { InjectModel } from 'nestjs-typegoose';
import { Student } from '@app/db/models/Student.model';
import { ModelType } from '@typegoose/typegoose/lib/types';

@Injectable()
export class StudentsService {
  constructor(
    @InjectModel(Student) private readonly student: ModelType<Student>,
  ) {}

  async findAll(): Promise<Student[]> {
    return this.student.find();
  }

  async findOne(stuId: string): Promise<Student> {
    return this.student.findOne({ stuId });
  }

  async createStu(student: Student): Promise<Student> {
    return this.student.create(student);
  }

  async insertMany(students: Student[]): Promise<Student[]> {
    return this.student.insertMany(students);
  }

  async updateStu(id: string, student: Student) {
    return this.student.findByIdAndUpdate(id, student);
  }

  async removeStu(id: string): Promise<Student> {
    return this.student.findByIdAndRemove(id);
  }
}
